<template>
  <div>
      <!--代码雨区域-->
      <canvas id="canvas" style="background:#000"></canvas>
      <!-- 登录页 -->
      <div class="login-container">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-position="left" label-width="0px" class="login-main">
          <h3 class="title">登录验证</h3>
          <el-form-item prop="account">
            <el-input type="text" v-model="ruleForm.account" auto-complete="off" placeholder="账号"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input type="password" v-model="ruleForm.password" auto-complete="off" placeholder="密码"></el-input>
          </el-form-item>
          <el-form-item class="btn-box">
            <el-button type="primary" @click="submitLogin('ruleForm')">登录</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
  </div>
</template>

<script>
// 代码雨
window.onload = function () {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
// 浏览器宽高
var W = window.screen.availWidth;
var H = window.screen.availHeight;
canvas.width = W;
canvas.height = H;
var fontSize = 18;
var colunms = Math.floor(W / fontSize);
// 坐标
var coordinate = [];
for (var i = 0; i < colunms; i++) {
coordinate.push(0);
}
var str = "javascript html5 canvas";
function draw() {
// 背景色
context.fillStyle = "rgba(0,0,0,0.05)";
context.fillRect(0, 0, W, H);
context.font = "800 " + fontSize + "px  宋体";
// 字体颜色
context.fillStyle = "#01fef5";
for (var i = 0; i < colunms; i++) {
	var index = Math.floor(Math.random() * str.length);
	var x = i * fontSize;
	var y = coordinate[i] * fontSize;
	context.fillText(str[index], x, y);
	if (y >= canvas.height && Math.random() > 0.88) {
		coordinate[i] = 0;
	}
	coordinate[i]++;
}
}

function randColor() {
var r = Math.floor(Math.random() * 256);
var g = Math.floor(Math.random() * 256);
var b = Math.floor(Math.random() * 256);
return "rgb(" + r + "," + g + "," + b + ")";
}

draw();
setInterval(draw, 30);
};
// 代码js雨结束
export default {
  data () {
    return {
      ruleForm: {
        account: '',
        password: ''
      },
      rules: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitLogin (formName) {
      this.$refs[formName].validate((valid) => {
        console.log(valid, 'validvalid')
        if (valid) {
          this.$message({
            message: '登陆成功',
            type: 'success',
            duration: 2000
          })
          this.$router.push({ path:'/Home'  })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  },
  mounted(){
    // window.location.reload();
  }
}
</script>

<style lang="scss">
body {
	margin: 0;
	padding: 0;
	overflow:hidden;
}
#canvas{
  margin-top: -60px;
}
.login-container{
  position:fixed;
	left:35%;
	top:35%;
  opacity: 0.8;
  // background-image:url('../assets/logo.png'); 
  background-size: cover; 
  // overflow: hidden;
  .login-main{ 
    -webkit-border-radius: 5px;
     -moz-border-radius: 5px; 
     border-radius: 5px; 
     background-clip: padding-box; 
    //  margin: 280px auto; 
     padding: 35px 35px 15px;
     width: 350px;  
     background: #fff; 
     border: 1px solid #eaeaea; 
     box-shadow: 0 0 25px #cac6c6;
    h3{text-align: center;}
    .btn-box{
      text-align: center;
      }
  }
}
</style>
